<?php

namespace app\middleware;


use app\Request;

/**
 * 全局中间件 数据统一管理
 * @package app\middleware
 * User: liuhongbin
 * Date: 2021-09-22 11:19
 */
class DkMiddleware
{
    /**
     * @param Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle(Request $request, \Closure $next)
    {
        $request->global = [
            'access-token' => $request->header('access-token'),
            'addon-name'   => $request->header('addon-name'),
            'plaid'        => $request->header('plaid'),
        ];

//        // 检查请求方法是否为 OPTIONS
//        if ($request->method('OPTIONS')) {
//            // 返回允许跨域的响应
//            return response('', 200, [
//                'Access-Control-Allow-Origin'      => "*",
//                'Access-Control-Allow-Credentials' => 'true',
//                'Access-Control-Allow-Headers'     => '*',
//                'Access-Control-Allow-Methods'     => '*',
//            ]);
//        }

        $response = $next($request);
//        $response->header([
//            'Access-Control-Allow-Origin'      => "*",
//            'Access-Control-Allow-Credentials' => 'true',
//            'Access-Control-Allow-Headers'     => '*',
//            'Access-Control-Allow-Methods'     => '*',
//        ]);
        return $response;
    }
}
